package cn.sdormitory.common.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;
import java.util.function.Function;

public class PageUtil {
    public static <T,R> IPage<R> convertPage(IPage<T> page, Function<T,R> beanConvert){
        if(page == null){
            return null;
        }
        @SuppressWarnings({"UnnecessaryLocalVariable", "rawtypes"})
        IPage tmp = page;
        List<R> records = ContainerUtil.mapList(page.getRecords(), beanConvert);
        page.setRecords(null);
        @SuppressWarnings("unchecked")
        IPage<R> ret = tmp;
        ret.setRecords(records);
        return ret;
    }
}
